﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZeroBug.EasyFlow.Core
{
    public class VariableJudge
    {
        private VariableManager _variableManager;
        public VariableExpression SourceVariable { get; set; }
        public VariableExpression CompareVariable { get; set; }
        public CompareSign Sign { get; set; }
        public bool IsReverse { get; set; }
        public bool IsEnable { get; set; }
        public bool Result => GetResult();
        public int CompareIndex { get; set; } = 0;
        public string Alias { get; set; }
        public void SetVariableManager(VariableManager variableManager)
        {
            this._variableManager = variableManager;
        }
        public bool GetResult()
        {
            if (!IsEnable) return true;
            bool result = SourceVariable.GetEquivalent().CompareTo(Sign, CompareVariable.GetEquivalent(), CompareIndex);
            if (IsReverse) return !result;
            return result;
        }
        public override string ToString()
        {
            return $"{SourceVariable} {EnumHelper.GetEnumDescriptionFromValue(Sign)} {CompareVariable}";
        }
    }
}
